﻿namespace SGLib.Scene
{
    public class BaseScene
    {
        protected BaseSceneLoader SceneLoader;
        /// <summary>
        /// 场景初始化
        /// </summary>
        /// <param name="args"></param>
        public virtual void OnInit(params object[] args) { }
        /// <summary>
        /// 启动场景
        /// </summary>
        public virtual void Enter() 
        {
            if (this.SceneLoader != null)
            {
                this.SceneLoader.LoadFinishEvent += this.OnLoad;
                this.SceneLoader.OnStart();
            }
            else 
            {
                this.OnLoad();
            }
        }
        public bool IsLoad = false;
        /// <summary>
        /// 场景加载成功
        /// </summary>
        public virtual void OnLoad()
        {
            this.IsLoad = true;
           
        }
       
        /// <summary>
        /// 退出场景
        /// </summary>
        public virtual void OnExit()
        {
           
        }

        public virtual void OnUpdate() 
        {
            if (this.SceneLoader != null&&!this.SceneLoader.IsFinish) 
            {
                this.SceneLoader.OnUpdate();
            }
        }
    }

    public class BaseSceneLoader 
    { 
        public event System.Action LoadFinishEvent;
        public bool IsFinish  = false;
        public bool IsStart  = false;
        public virtual void OnStart() 
        {
            this.IsStart = true;
        }
        public virtual void OnUpdate() { }
        public virtual void OnFinish() 
        {
            if(IsFinish ==true)
            {
              return;
            }
            IsFinish = true;
            if (this.LoadFinishEvent != null) 
            {
                this.LoadFinishEvent();
            }
        }
    }
}